package cn.legend.travel.destination.main.controller;

import cn.legend.travel.common.pojo.po.DistrictSimplePO;
import cn.legend.travel.common.pojo.po.DistrictSimplesPO;
import cn.legend.travel.common.pojo.po.SceneriesPO;
import cn.legend.travel.common.web.JsonResult;
import cn.legend.travel.destination.main.service.IDistrictService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处理省市区相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/dict/district")
@Validated
@Api(tags = "1.省市区")
public class DistrictController {

    @Autowired
    private IDistrictService districtService;

    public DistrictController() {
        log.debug("创建控制器类对象：DistrictController");
    }

    @GetMapping("/list")
    @ApiOperation("查询目的地列表")
    @ApiOperationSupport(order = 420)
    public JsonResult listByParent() {
        List<DistrictSimplesPO> districtList = districtService.list();
        return JsonResult.ok(districtList);
    }

    @GetMapping("/listFromRegion")
    @ApiOperation("查询热门目的地列表")
    @ApiOperationSupport(order = 430)
    public JsonResult listFromRegion() {
        List<DistrictSimplePO> districtList = districtService.listFromRegion();
        return JsonResult.ok(districtList);
    }

    @GetMapping("/list-by-name")
    @ApiOperation("根据名称查询目的地列表")
    @ApiOperationSupport(order = 440)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "目的地，默认为北京", required = true, dataType = "String", example = "北京")
    })
    public JsonResult selectByName(@RequestParam String name) {
        log.debug("开始处理【根据名称查询目的地列表】的请求");
        SceneriesPO sceneriesPO = districtService.selectByName(name);
        return JsonResult.ok(sceneriesPO);
    }

    @GetMapping("/listFromScenery")
    @ApiOperation("根据名称,页码查询目的地列表")
    @ApiOperationSupport(order = 450)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "目的地，默认为北京", required = true, dataType = "String", example = "北京"),
            @ApiImplicitParam(name = "num", value = "页码", required = true, dataType = "Integer", example = "1")
    })
    public JsonResult selectByNameAndPageable(@RequestParam String name, @RequestParam Integer num) {
        log.debug("开始处理【根据名称，页码查询目的地列表】的请求");
        SceneriesPO sceneriesPO = districtService.selectByNameAndPageable(name, num);
        return JsonResult.ok(sceneriesPO);
    }

}
